﻿using System.Collections;
using System.Collections.Generic;
using Com.FastSearch.Esp.Search.Result;

namespace ESPWebPartsUnitTest.mock
{
    class DocumentSummaryMock: IDocumentSummary
    {
        private readonly int docNo;
        private ArrayList docsFields = null;
        //private ArrayList docs = null;
        private Dictionary<string, DocumentSummaryFieldMock> dict;

        public  DocumentSummaryMock(int numFields, int docNum)
        {
            docNo = docNum;
            CreateMockDoc(numFields);
        }


        public void CreateMockDoc(int numFields)
        {
            dict = new Dictionary<string, DocumentSummaryFieldMock>();
            docsFields = new ArrayList();
            for (int i=0; i < numFields;i++)
            {
                AddSummary("Field" + i, "Value" + i, "Summary " + i);
                //docsFields.Add("Field" + i);
                //dict.Add("Field"+i, new DocumentSummaryFieldMock("Field"+i, "Value"+i, "Summary " + i));
            }

            // Add some special fields which are exposed as properties
            AddSummary("body", "<b>This</b> is the body with some <b>highlighting</b>", "<b>This</b> is the body with some <b>highlighting</b>");
            AddSummary("url", "http.//test.com/", "http.//test.com/" + DocNo);
            AddSummary("title", "<b>Title</b> with some <b>highlighting</b>", "<b>Title</b> with some <b>highlighting</b>" + DocNo);
            //AddSummary("Author", "MyAuthor", "MyAuthorSummray");
            //AddSummary("Modified", "Today", "");
            //AddSummary("Description", "MyDescription", "");

        }

        public void AddSummary(string field, string value, string summary)
        {
            if (docsFields.Contains(field))
            {
                docsFields.Remove(field);
                dict.Remove(field);
            } 
            docsFields.Add(field);
            dict.Add(field, new DocumentSummaryFieldMock(field, value, summary));
        }

        public int FieldCount()
        {
            return docsFields.Count;
        }

        public IDocumentSummaryField GetSummaryField(int i)
        {
            return dict[(string)docsFields[i]];
        }

        public IDocumentSummaryField GetSummaryField(string name)
        {
            return dict[name];
        }

        public IEnumerator SummaryFields()
        {
            return dict.GetEnumerator();
            //throw new NotImplementedException();
        }

        public IEnumerator GetEnumerator()
        {
            return dict.GetEnumerator();
            //throw new NotImplementedException();
        }

        public int DocNo
        {
            get { return docNo; }
        }
    }
}